package hr.ctg.domain.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

/**
 * Rola generated by MyEclipse Persistence Tools
 */
@Entity
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Table(name = "rola", uniqueConstraints = {})
public class Rola implements java.io.Serializable {
	public static enum Role {
		ADMIN(1), KORISNIK(2), POSLOVNI_OGLASIVAC(3), PRIVATNI_OGLASIVAC(4);

		private Integer id;

		Role(final int id) {
			this.id = id;
		}

		@Override
		public String toString() {
			return id.toString();
		}
	};

	// Fields
	private static final long serialVersionUID = 4578738299364467337L;

	private Integer idRole;
	private String naziv;
	private Set<Korisnik> korisniks = new HashSet<Korisnik>(0);

	// Constructors

	/** default constructor */
	public Rola() {

	}

	/** minimal constructor */
	public Rola(final Integer idRole, final String naziv) {
		this.idRole = idRole;
		this.naziv = naziv;
	}

	/** full constructor */
	public Rola(final Integer idRole, final String naziv,
			final Set<Korisnik> korisniks) {
		this.idRole = idRole;
		this.naziv = naziv;
		this.korisniks = korisniks;
	}

	// Property accessors
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id_role", unique = true, nullable = false, insertable = true, updatable = true)
	public Integer getIdRole() {
		return idRole;
	}

	public void setIdRole(final Integer idRole) {
		this.idRole = idRole;
	}

	@Column(name = "naziv", unique = false, nullable = false, insertable = true, updatable = true, length = 50)
	public String getNaziv() {
		return naziv;
	}

	public void setNaziv(final String naziv) {
		this.naziv = naziv;
	}

	@ManyToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
	@JoinTable(name = "korisnik_rola", joinColumns = { @JoinColumn(name = "id_role", unique = false, nullable = false, insertable = true, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "id_korisnika", unique = false, nullable = false, insertable = true, updatable = false) })
	public Set<Korisnik> getKorisniks() {
		return korisniks;
	}

	public void setKorisniks(final Set<Korisnik> korisniks) {
		this.korisniks = korisniks;
	}

}